Must pass the format string to strftime in the C library's locale's
authorTor Lillqvist <tml@novell.com>
Thu, 21 Feb 2008 12:47:45 +0000 (12:47 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Thu, 21 Feb 2008 12:47:45 +0000 (12:47 +0000)
2008-02-21  Tor Lillqvist  <tml@novell.com>

* gtk/gtkfilechooserdefault.c (list_mtime_data_func) [Win32]: Must
pass the format string to strftime in the C library's locale's
charset, not the system's. Correspondingly, the return value from
strftime() is in the C library's locale's charset. (#509885)

svn path=/trunk/; revision=19625

ChangeLog
gtk/gtkfilechooserdefault.c

index 21e3663a2a556b9933655a2492568dfabf2c8ffe..2bb73c128076cf49d43a79002a18d2e5649e28c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-21  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/gtkfilechooserdefault.c (list_mtime_data_func) [Win32]: Must
+       pass the format string to strftime in the C library's locale's
+       charset, not the system's. Correspondingly, the return value from
+       strftime() is in the C library's locale's charset. (#509885)
+
 2008-02-20  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkwindow-quartz.c: (gdk_window_set_decorations): Set
index d45043b33345900accb624811c732e1d01d7affe..d4bb4dddd9f8818c6c835c140d1b43ea23d2ec97 100644 (file)
@@ -73,6 +73,7 @@
 #if defined (G_OS_UNIX)
 #include "gtkfilesystemunix.h"
 #elif defined (G_OS_WIN32)
+#include <windows.h>
 #include "gtkfilesystemwin32.h"
 #endif
 
@@ -10974,6 +10975,11 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
   time_t time_mtime;
   gchar *date_str = NULL;
   gboolean sensitive = TRUE;
+#ifdef G_OS_WIN32
+  const char *locale, *dot = NULL;
+  gint64 codepage = -1;
+  char charset[20];
+#endif
 
   impl = data;
 
@@ -11092,10 +11098,46 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column,
            format = "%x"; /* Any other date */
        }
 
+#ifdef G_OS_WIN32
+      /* g_locale_from_utf8() returns a string in the system
+       * code-page, which is not always the same as that used by the C
+       * library. For instance when running a GTK+ program with
+       * LANG=ko on an English version of Windows, the system
+       * code-page is 1252, but the code-page used by the C library is
+       * 949. (It's GTK+ itself that sets the C library locale when it
+       * notices the LANG environment variable. See gtkmain.c The
+       * Microsoft C library doesn't look at any locale environment
+       * variables.) We need to pass strftime() a string in the C
+       * library's code-page. See bug #509885.
+       */
+      locale = setlocale (LC_ALL, NULL);
+      if (locale != NULL)
+       dot = strchr (locale, '.');
+      if (dot != NULL)
+       {
+         codepage = g_ascii_strtoll (dot+1, NULL, 10);
+         
+         /* All codepages should fit in 16 bits AFAIK */
+         if (codepage > 0 && codepage < 65536)
+           {
+             sprintf (charset, "CP%u", (guint) codepage);
+             locale_format = g_convert (format, -1, charset, "UTF-8", NULL, NULL, NULL);
+           }
+       }
+#else
       locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
-
-      if (strftime (buf, sizeof (buf), locale_format, &tm_mtime) != 0)
-        date_str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
+#endif
+      if (locale_format != NULL &&
+         strftime (buf, sizeof (buf), locale_format, &tm_mtime) != 0)
+        {
+#ifdef G_OS_WIN32
+         /* As above but in opposite direction... */
+         if (codepage > 0 && codepage < 65536)
+           date_str = g_convert (buf, -1, "UTF-8", charset, NULL, NULL, NULL);
+#else
+         date_str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
+#endif
+       }
       else
        date_str = g_strdup (_("Unknown"));